package util;

import model.UserInfo;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author shkstart
 * 获取登录的用户
 * @create 2023-01-16-23:06
 */
public class SessionUtils {
    public static UserInfo getLoginUser(HttpServletRequest req) {
        UserInfo userInfo = null;
        //得到当前的session，验证登录用false，登录用true
        HttpSession session = req.getSession(false);
        if (session != null && session.getAttribute(AppVar.SESSION_USERINFO_KEY) != null) {
            //此时处于登录状态
            userInfo = (UserInfo) session.getAttribute(AppVar.SESSION_USERINFO_KEY);

        }
        return userInfo;
    }
}
